

cap program drop PlotCoeffCPS
program define PlotCoeffCPS
syntax, TITLE(string) NAME(string) XLINE(real) [INLEVELS] [AUTOLABEL] [YTI(string)] [XTI(string)] VRS(string)

	mat b = e(b)
	mat s = e(V)

	foreach vr in `: colnames b' {
		
		local iter = `iter'+1
		
		mat x = b[1,"`vr'"]
		local beta = x[1,1]

		mat y = s[`iter',"`vr'"]
		local se = sqrt(y[1,1])

		local obs`iter' "`: colnames x'|`beta'|`se'"

		macro drop _beta _se
		mat drop x y
	}
	
	preserve

		clear
		qui set obs `iter'
		qui gen ind=""
		forval vl = 1/`iter' {
			qui replace ind="`obs`vl''" in `vl'
			macro drop _obs`vl'
		}
		macro drop _iter
		
		qui split ind, parse("|")
		qui keep if regexm(ind1,"`vrs'")==1
		
		qui gen beta=ind2
		qui gen se=ind3
		
		qui split ind1, parse("_") 
		qui gen date=ind12

		keep beta se date

		qui destring _all, replace
		confirm numeric var date beta se
						
		gen ind=1
		qui tsset ind date
		tsfill
		qui replace beta=0 if beta==.
		drop ind
				
		qui gen low=beta-(1.96*se)
		qui gen hi=beta+(1.96*se)
		
		format date %tm
		/*
		if "`inlevels'"=="inlevels" local ylabel "ylabel(-0.4 -.2 0 .2 .4 .6 .8 1 1.2 1.4)"
		else local ylabel "ylabel(-0.08 -0.06 -0.04 -.02 0 .02 .04 .06 .08 0.1)"
		
		local ylabel "ylabel(-0.1 -.05 0 .1 .2 .3)"
		local ylabel "ylabel(-0.1 -.05 0 .05 .1 .15 .2)"	
		local ylabel "ylabel(-.04 -.02 0 .02 .04 .06 .08 .1)"	
		
		if "`autolabel'"=="autolabel" macro drop _ylabel
		local ylabel "ylabel(-.75 -.5 -.25 0 .25 .5 .75 1) " // edited line
*/
		if "`yti'"!=""   local yti `"`yti'"'
					else local yti "Estimated effect on log hourly wages"

		#d 
			twoway rcap hi low date || connected beta date,
			yline(0, lcolor(black) lw(vthin))
			xline(`xline') legend(off) name(`name', replace) title(`title')
			`ylabel' graphregion(color(white)) xlabel(#7) 
			xti("`xti'") 
			yti("`yti'")
		;
		#d cr
		
	restore

	mat drop b s
	
end

